package com.yy.bootdemo.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yy.bootdemo.admin.entity.ScdCostAdministrationEntity;
import com.yy.bootdemo.admin.service.ScdCostAdministrationService;
import com.yy.bootdemo.security.utils.PageUtils;
import com.yy.bootdemo.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;


/**
 * 
 *
 * @author yy
 * @email yangxxil01@sina.com
 * @date 2021-12-02 08:55:44
 */
@RestController
@RequestMapping("city")
public class ScdCostAdministrationController {
    @Autowired
    private ScdCostAdministrationService scdCostAdministrationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestBody PageUtils params){
        // 条件构造器
        QueryWrapper<ScdCostAdministrationEntity> userQuery = Wrappers.query();
        //userQuery.ge("age", 26);

        Page<ScdCostAdministrationEntity> page = new Page<>(params.getCurrent(), params.getSize());

        IPage<ScdCostAdministrationEntity> userPage = scdCostAdministrationService.page(page, userQuery);
        System.out.println("总页数：" + userPage.getPages());
        System.out.println("总记录数：" + userPage.getTotal());
        System.out.println();
        List<ScdCostAdministrationEntity> userList = userPage.getRecords();
        userList.forEach(System.out::println);
        return R.ok(userPage);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{administrationId}")
    public R info(@PathVariable("administrationId") Integer administrationId){
		ScdCostAdministrationEntity scdCostAdministration = scdCostAdministrationService.getById(administrationId);

        return R.ok().put("scdCostAdministration", scdCostAdministration);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ScdCostAdministrationEntity scdCostAdministration){
		scdCostAdministrationService.save(scdCostAdministration);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ScdCostAdministrationEntity scdCostAdministration){
		scdCostAdministrationService.updateById(scdCostAdministration);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] administrationIds){
		scdCostAdministrationService.removeByIds(Arrays.asList(administrationIds));

        return R.ok();
    }

}
